Mostramos como usar plotly a partir de una grΓ‘fica de ggplot2, ademΓ‘s veremos como agregar emojis con el paquete emo π¦Ή
library(tidyverse)
library(plotly)
library(emo)
movies <- read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2018/2018-10-23/movie_profit.csv')
# creamos una tabla que contenga ΓΊnicamente las pelΓculas de terror con
# ganancia y presupuesto positivos
# creamos ademΓ‘s una variable de aΓ±o en que se estrenΓ³
movies_horror <- movies %>%
filter(genre == "Horror", worldwide_gross > 0, production_budget > 0) %>%
mutate(year = as.numeric(str_sub(release_date, start = -1L - 3, end = -1L)))
gg_horror <- ggplot(movies_horror, aes(x = production_budget,
y = worldwide_gross, color = year)) +
geom_point() +
theme_minimal() +
scale_x_log10() +
scale_y_log10() +
facet_wrap(~ mpaa_rating)
gg_horror
ggplotly(gg_horror)
emo para incluir emojis en los datos# Creamos una columna de emojis con el paquete emojifont!
movies_horror <- movies_horror %>%
mutate(figure = case_when(
mpaa_rating == "PG" ~ "jack_o_lantern",
mpaa_rating == "PG-13" ~ "ghost",
mpaa_rating == "R" ~ "skull",
TRUE ~ "imp"),
emoji = map_chr(figure, emo::ji))
glimpse(movies_horror)
## Rows: 295
## Columns: 12
## $ ...1 <dbl> 43, 67, 233, 272, 287, 349, 386, 429, 452, 454, 475,β¦
## $ release_date <chr> "12/14/2007", "2/12/2010", "5/19/2017", "8/4/2000", β¦
## $ movie <chr> "I am Legend", "The Wolfman", "Alien: Covenant", "Hoβ¦
## $ production_budget <dbl> 1.50e+08, 1.50e+08, 9.70e+07, 9.00e+07, 8.70e+07, 8.β¦
## $ domestic_gross <dbl> 256393010, 62189884, 74262031, 73209340, 165092266, β¦
## $ worldwide_gross <dbl> 585532684, 142634358, 238521247, 191200000, 35010028β¦
## $ distributor <chr> "WarnerΒ Bros.", "Universal", "20thΒ CenturyΒ Fox", "Soβ¦
## $ mpaa_rating <chr> "PG-13", "R", "R", "R", "R", "PG-13", "R", "PG-13", β¦
## $ genre <chr> "Horror", "Horror", "Horror", "Horror", "Horror", "Hβ¦
## $ year <dbl> 2007, 2010, 2017, 2000, 2001, 1999, 2004, 1998, 1999β¦
## $ figure <chr> "ghost", "skull", "skull", "skull", "skull", "ghost"β¦
## $ emoji <chr> "π»", "π", "π", "π", "π", "π»", "π", "π»", "π"β¦
gg_horror_emo <- ggplot(movies_horror, aes(text = emoji,
x = production_budget,
y = worldwide_gross, color = year,
label = movie)) +
geom_point() +
theme_minimal() +
scale_x_log10() +
scale_y_log10() +
facet_wrap(~ mpaa_rating)
ggplotly(gg_horror_emo, tooltip = c("emoji", "movie", "year"))